﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GraduationProject.Model
{
    /// <summary>
    /// 评论表
    /// </summary>
    public class Comment
    {
        /// <summary>
        /// 评论表ID
        /// </summary>
        public int CommentID { get; set; }
        /// <summary>
        /// 评论文章ID
        /// </summary>
        public int NovelID { get; set; }
        /// <summary>
        /// 评论内容
        /// </summary>
        public string CommentBody { get; set; }
        /// <summary>
        /// 目标评论ID
        /// </summary>
        public int GoalCommentID { get; set; }
        /// <summary>
        /// 点赞数
        /// </summary>
        public int AgreeNum { get; set; }
        /// <summary>
        /// 反对数
        /// </summary>
        public int DisagreeNum { get; set; }
        /// <summary>
        /// 投票用户
        /// </summary>
        public int VoteUser { get; set; }
        /// <summary>
        /// 评论时间
        /// </summary>
        public DateTime CreateTime { get; set; }
        /// <summary>
        /// 评论人
        /// </summary>
        public int CreateUser { get; set; }
        /// <summary>
        /// 评论人昵称
        /// </summary>
        public string CreateUserName { get; set; }
        /// <summary>
        /// 评论人头像
        /// </summary>
        public string CreateUserHeadPortrait { get; set; }
        /// <summary>
        /// 子评论
        /// </summary>
        public List<Comment> Comments { get; set; } = new List<Comment>();


        /// <summary>
        /// 尝试将评论添加到子评论中
        /// </summary>
        /// <param name="SourceComment"></param>
        /// <returns></returns>
        public bool TrySetComments(Comment SourceComment)
        {
            if (SourceComment != null)
            {
                if (SourceComment.GoalCommentID == this.CommentID)
                {
                    this.Comments.Add(SourceComment);
                    return true;
                }
                else
                {
                    foreach (var item in Comments)
                    {
                        if (item.TrySetComments(SourceComment))
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    }
}
